import { Global, Module } from '@nestjs/common';
import { DbService } from './db.service';
import { TypeOrmModule, TypeOrmModuleOptions } from '@nestjs/typeorm';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { DictionaryCategoryRepositoryModule } from '@app/db/common/dictionary-category-repository/dictionary-category-repository.module';
import { DictionaryItemRepositoryModule } from '@app/db/common/dictionary-item-repository/dictionary-item-repository.module';
import { SysConfigRepositoryModule } from '@app/db/common/sys-config-repository/sys-config-repository.module';
import { UserRepositoryModule } from '@app/db/user-repository/user-repository.module';
import { OfficialUserModule } from '@app/db/official-user/official-user.module';

@Global()
@Module({
    imports : [
        TypeOrmModule.forRootAsync({
            imports : [ConfigureModule],
            inject : [ConfigureService],
            useFactory : (config:ConfigureService) => {
                
                return {
                    ...config.get<TypeOrmModuleOptions>('db')
                }
            },
        }),

        SysConfigRepositoryModule,
        DictionaryCategoryRepositoryModule,
        DictionaryItemRepositoryModule,

        UserRepositoryModule,
        OfficialUserModule,
    ],
    providers: [DbService],
    exports : [DbService]
})
export class DbModule {}
